#include "Button.h"

Button::Button(std::string buttonName, std::string path, int posX, int posY,
		Widget *parent, Listener* listener) :
		WidgetClickeableWithText(buttonName,path,posX, posY, parent) {

	this->listener = listener;
}

Button::~Button() {
}

void Button::handleEvent(Event event) {
	if (!isMouseOver(event))
		return;


	if ((event.getType()) == MouseButtonPressed) {
		this->pressed = true;
		Logger::log("Button", "handleEvent", "MOUSEBUTTONDOWN");
	} else if ((event.getType()) == MouseButtonReleased) {
		this->pressed = false;
		Logger::log("Button", "handleEvent", "SDL_MOUSEBUTTONUP");
	}
}

void Button::resolve() {
	if (this->pressed) {
		this->listener->execute();
	}
}

void Button::showOn(SDL_Surface *surface) {
	SDL_Rect rect;
	rect.x = parcel.posX;
	rect.y = parcel.posY;
	rect.w = parcel.width;
	rect.h = parcel.height;
	SDL_BlitSurface(this->surface, NULL, surface, &rect);
}
